var userid = '';

$(function() {

	userid = getUrlParam("userid");
	
//	var user = parent.getData(userid);
//	alert(user.username);
	bindUserForm();

	initTable();
})


function bindUserForm(){
	var user = parent.getData(userid);
	
	for(var u in user){
		$('#' + u).html(user[u]);
	}
}


function save() {
	var params = {};

	var user = parent.getData(userid);
	var data = $('#table').bootstrapTable('getSelections');

	params['user'] = user;
	params['role'] = data;
	
//	return true;

	$.ajax({
		method : 'post',
		url : projectPath + "user/right.do",
		data : JSON.stringify(params),
		dataType : "json",
		contentType : "application/json",
		success : function(data) {
	    	if(data.result == 1){
				window.wxc.xcConfirm(data.info, window.wxc.xcConfirm.typeEnum.success);	
	    	} 
	    	else{
	    		window.wxc.xcConfirm(data.info, window.wxc.xcConfirm.typeEnum.error);
	    	}
		}
	});
}

function check(declareData){
	var result = true;
	

	if($('#tableMaterial').find('tbody').find('tr').not('.no-records-found').length == 0){
		$.alert('请增加<span style="color:red;"><strong>行政许可材料</strong></span>的行数据！');
		
		return false;
	}
	
	
	var mustStr = "itemtypecode,itemname,materialname,typecode,verifymethod";
	
	var strMsg = "";
	var mustStrs = mustStr.split(',');
	for(var i=0; i<mustStrs.length; i++){
		var obj = $('[name="'+mustStrs[i]+'"]');
		if(obj.val() == ""){
			strMsg += obj.attr("placeholder") + "！<br />";
			
			result = false;
		}
	}
	

	
	
	if(strMsg != ""){
		$.alert(strMsg);
	}
	
	return result;
}




function initTable(){		
	$('#table').bootstrapTable({
		method: 'post',
	    url: basePath() + 'user/userrole.do',
	    pagination: true, //分页
	    dataType: "json",
        contentType: "application/json",
        pageList: [100],  //可供选择的每页的行数（*）
        striped: true,      //是否显示行间隔色
        sidePagination: "server",
        ////查询参数,每次调用是会带上这个参数，可自定义                         
        queryParams:function(params) {
            return {
                	userid: userid
                };
        },
	    columns: [{
            field : 'checked',
            checkbox : true,
            formatter : function(value, row, index) {
            	var ischeck = row.ischeck;
            	return ischeck;
		    }   
        }, {  
            field : 'number',  
            title : '序号',  
            align : 'center',
            width : '80px',
            formatter : function(value, row, index) {  
// 		                return index + 1;  
                var page = $('#table').bootstrapTable("getPage");  
                return page.pageSize * (page.pageNumber - 1) + index + 1;  
            }  
        }, {
	        field: 'rolecode',
	        title: '角色代码'
	    }, {
	        field: 'rolename',
	        title: '角色名称'
	    },  {
	        field: 'roletype',
	        title: '角色类型',
	        formatter:function(value,row,index){
	        	return  value == "01" ? "系统角色" : "4A角色";
	        }
	    }]
	});
}

